home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD15883342001.psc / File Transfer / frmServer.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  2001-02-04  |  14.6 KB  |  370 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  4. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  5. Begin VB.Form frmServer 
  6.    BorderStyle     =   1  'Fixed Single
  7.    Caption         =   "Server"
  8.    ClientHeight    =   8190
  9.    ClientLeft      =   45
  10.    ClientTop       =   330
  11.    ClientWidth     =   7095
  12.    LinkTopic       =   "Form2"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   8190
  16.    ScaleWidth      =   7095
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin VB.CommandButton cmdRemove 
  19.       Caption         =   "&Remove File"
  20.       Height          =   495
  21.       Left            =   3960
  22.       TabIndex        =   13
  23.       Top             =   3960
  24.       Width           =   1215
  25.    End
  26.    Begin VB.ListBox lstSend 
  27.       Height          =   3375
  28.       Left            =   3720
  29.       TabIndex        =   11
  30.       Top             =   360
  31.       Width           =   3255
  32.    End
  33.    Begin VB.CommandButton cmdAddFile 
  34.       Caption         =   "&Add File"
  35.       Height          =   495
  36.       Left            =   1080
  37.       TabIndex        =   10
  38.       Top             =   3960
  39.       Width           =   1215
  40.    End
  41.    Begin VB.FileListBox lstFiles 
  42.       Height          =   1455
  43.       Left            =   120
  44.       System          =   -1  'True
  45.       TabIndex        =   7
  46.       Top             =   2400
  47.       Width           =   3135
  48.    End
  49.    Begin VB.DirListBox lstDir 
  50.       Height          =   1665
  51.       Left            =   120
  52.       TabIndex        =   8
  53.       Top             =   720
  54.       Width           =   3135
  55.    End
  56.    Begin VB.DriveListBox lstDrive 
  57.       Height          =   315
  58.       Left            =   120
  59.       TabIndex        =   6
  60.       Top             =   360
  61.       Width           =   3135
  62.    End
  63.    Begin VB.CommandButton cmdSendChat 
  64.       Caption         =   "Send Chat"
  65.       Default         =   -1  'True
  66.       Height          =   255
  67.       Left            =   5760
  68.       TabIndex        =   5
  69.       Top             =   7800
  70.       Width           =   1215
  71.    End
  72.    Begin VB.TextBox txtSend 
  73.       Height          =   285
  74.       Left            =   120
  75.       TabIndex        =   4
  76.       Top             =   7800
  77.       Width           =   5535
  78.    End
  79.    Begin VB.TextBox txtChat 
  80.       Height          =   1575
  81.       Left            =   120
  82.       Locked          =   -1  'True
  83.       MultiLine       =   -1  'True
  84.       ScrollBars      =   2  'Vertical
  85.       TabIndex        =   3
  86.       Top             =   6120
  87.       Width           =   6855
  88.    End
  89.    Begin VB.CommandButton cmdSend 
  90.       Caption         =   "&Send File"
  91.       Height          =   495
  92.       Left            =   5520
  93.       TabIndex        =   0
  94.       Top             =   3960
  95.       Width           =   1215
  96.    End
  97.    Begin VB.Timer tmrKBps 
  98.       Interval        =   1000
  99.       Left            =   0
  100.       Top             =   8400
  101.    End
  102.    Begin MSComDlg.CommonDialog CD 
  103.       Left            =   120
  104.       Top             =   8160
  105.       _ExtentX        =   847
  106.       _ExtentY        =   847
  107.       _Version        =   393216
  108.    End
  109.    Begin MSWinsockLib.Winsock Winsock 
  110.       Left            =   0
  111.       Top             =   8760
  112.       _ExtentX        =   741
  113.       _ExtentY        =   741
  114.       _Version        =   393216
  115.    End
  116.    Begin MSComctlLib.ProgressBar PBar 
  117.       Height          =   735
  118.       Left            =   240
  119.       TabIndex        =   1
  120.       Top             =   4800
  121.       Width           =   6615
  122.       _ExtentX        =   11668
  123.       _ExtentY        =   1296
  124.       _Version        =   393216
  125.       Appearance      =   1
  126.       Scrolling       =   1
  127.    End
  128.    Begin VB.ListBox lstPath 
  129.       Height          =   3375
  130.       Left            =   3720
  131.       TabIndex        =   14
  132.       Top             =   360
  133.       Width           =   3255
  134.    End
  135.    Begin VB.Label Label2 
  136.       Alignment       =   2  'Center
  137.       Caption         =   "Send Files"
  138.       BeginProperty Font 
  139.          Name            =   "MS Sans Serif"
  140.          Size            =   13.5
  141.          Charset         =   0
  142.          Weight          =   400
  143.          Underline       =   0   'False
  144.          Italic          =   0   'False
  145.          Strikethrough   =   0   'False
  146.       EndProperty
  147.       Height          =   375
  148.       Left            =   3960
  149.       TabIndex        =   12
  150.       Top             =   0
  151.       Width           =   2775
  152.    End
  153.    Begin VB.Label Label1 
  154.       Alignment       =   2  'Center
  155.       Caption         =   "Select Files"
  156.       BeginProperty Font 
  157.          Name            =   "MS Sans Serif"
  158.          Size            =   13.5
  159.          Charset         =   0
  160.          Weight          =   400
  161.          Underline       =   0   'False
  162.          Italic          =   0   'False
  163.          Strikethrough   =   0   'False
  164.       EndProperty
  165.       Height          =   375
  166.       Left            =   240
  167.       TabIndex        =   9
  168.       Top             =   0
  169.       Width           =   2775
  170.    End
  171.    Begin VB.Line Line2 
  172.       X1              =   3480
  173.       X2              =   3480
  174.       Y1              =   120
  175.       Y2              =   4560
  176.    End
  177.    Begin VB.Line Line1 
  178.       X1              =   120
  179.       X2              =   6960
  180.       Y1              =   4560
  181.       Y2              =   4560
  182.    End
  183.    Begin VB.Label lblKBps 
  184.       Alignment       =   2  'Center
  185.       Caption         =   "KBps:"
  186.       Height          =   255
  187.       Left            =   1200
  188.       TabIndex        =   2
  189.       Top             =   5640
  190.       Width           =   4455
  191.    End
  192. Attribute VB_Name = "frmServer"
  193. Attribute VB_GlobalNameSpace = False
  194. Attribute VB_Creatable = False
  195. Attribute VB_PredeclaredId = True
  196. Attribute VB_Exposed = False
  197. Option Explicit
  198. Dim strFriend As String 'holds servers name
  199. Dim strMyName As String 'holds your name
  200. Dim strFileName As String 'holds the name of the file u are receiving
  201. Dim strSize As String 'holds the size of the file
  202. Dim strSoFar As String 'a var for calculating the KBps
  203. Dim strBlock As String 'holds the data you are going to send
  204. Dim strLOF As String 'holds the lenght of the file
  205. Private Sub cmdAddFile_Click()
  206.     If lstFiles.ListIndex = -1 Then 'if nothing is selected
  207.         MsgBox "Please select a file, then click Add File", vbInformation, "Add File"
  208.     Else
  209.         lstSend.AddItem lstFiles.List(lstFiles.ListIndex)
  210.         lstPath.AddItem lstDir.Path
  211.     End If
  212. End Sub
  213. Private Sub cmdRemove_Click()
  214.     If lstSend.ListIndex = -1 Then 'if nothing is selected
  215.         MsgBox "Please select a file to remove, and then hit remove.", vbInformation, "Remove File"
  216.     Else
  217.         lstPath.RemoveItem lstSend.ListIndex
  218.         lstSend.RemoveItem lstSend.ListIndex
  219.     End If
  220. End Sub
  221. Private Sub cmdSendChat_Click()
  222.     If Trim(txtSend.Text) = "" Then Exit Sub 'prevents someone trying to send nothing
  223.     Winsock.SendData "Chat" & txtSend.Text 'sends the text to the chat
  224.     txtChat.SelStart = Len(txtChat) 'put focus on the chat at the end so it is entered in the right place
  225.     txtChat.SelText = strMyName & ":" & vbTab & txtSend.Text & vbCrLf 'puts the text in the chat
  226.     txtSend.Text = "" 'clears the textbox u type in
  227. End Sub
  228. Private Sub Form_Unload(Cancel As Integer)
  229.     Winsock.Close 'closes winsock so program can end
  230.     End 'closes program
  231. End Sub
  232. Private Sub lstDir_Change()
  233.     lstFiles.Path = lstDir.Path 'links them together
  234. End Sub
  235. Private Sub lstDrive_Change()
  236. On Error GoTo driveError 'if for example no disk is in the A: drive
  237.     lstDir.Path = lstDrive.Drive
  238.     Exit Sub
  239. driveError:
  240.     MsgBox "The current device is unavailable", vbCritical, "Error"
  241.     lstDrive.ListIndex = 1 'goes to the C: drive
  242. End Sub
  243. Private Sub tmrKBps_Timer()
  244. On Error Resume Next 'prevents error
  245.     lblKBps.Caption = "Transfering at: " & Format(strSoFar / 1000, "###0.0") & " / KBps" 'calculates the KBps
  246.     strSoFar = 0 'resets it so it can be calculated again
  247. End Sub
  248. Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
  249.     If Winsock.State <> sckClosed Then Winsock.Close 'closes winsock and allows it to accept a connection
  250.     Winsock.Accept requestID 'allows new connection
  251.     DoEvents 'hahaha
  252.     Winsock.SendData "Nick" & frmConnect.txtName.Text 'sends ur name to client
  253.     DoEvents 'keeps everything running smooth
  254.     strMyName = frmConnect.txtName 'saves ur name into memory
  255.     Me.Show 'shows frmserver
  256.     Unload frmConnect 'hmm what does that do?
  257. End Sub
  258. Private Sub cmdSend_Click()
  259. On Error Resume Next 'prevents error
  260.     strFileName = "" 'resets the filename
  261.     strSize = "" 'resets the size
  262. Dim intX As Integer
  263. Dim strFile, strPath As String
  264.         strFile = lstSend.List(0)
  265.         strPath = lstPath.List(0)
  266.         lstSend.RemoveItem 0
  267.         lstPath.RemoveItem 0
  268.         Open strPath & "\" & strFile For Binary As #1 'opens the file to be sent and reads it
  269.         strLOF = LOF(1) 'gets the length of the file
  270.         Winsock.SendData "Name" & strFile & ":" & strLOF 'sends the name of the first file and its length
  271. End Sub
  272. Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
  273. On Error Resume Next 'prevents error
  274. Dim strData As String 'holds data for select case
  275. Dim strData2 As String 'holds data
  276.     Call Winsock.GetData(strData, vbString) 'gets the data sent by the client
  277.     strData2 = Mid(strData, 5) 'gets data
  278.     strData = Left(strData, 4) 'gets data for select case
  279.     Select Case strData 'goes to the right case depending on strData
  280.         Case "File" 'a file transfer is in progress
  281.             Put 1, , strData2 'puts data into file
  282.             PBar.Value = PBar.Value + bytesTotal 'shows how much is done so far
  283.             strSoFar = strSoFar + bytesTotal 'calculates KBps
  284.             If Not LOF(1) >= PBar.Max Then
  285.                 Winsock.SendData "OKOK keep sending!" 'tells them ur done with the data and u want some more!
  286.                 DoEvents ' =D
  287.             End If
  288.         Case "Name" 'client has sent u the filename and is ready to begin transfer
  289.             Dim intX As Integer 'holds position if :
  290.             intX = InStr(1, strData2, ":", vbTextCompare) 'gets position of :
  291.             strSize = Mid(strData2, intX + 1) 'holds the filesize
  292.             PBar.Max = strSize 'sets up the progressbar
  293.             strData = Mid(strData2, 1, intX - 1) 'holds filename
  294.             strFileName = strData 'puts filename into memory
  295.             Dim strResponse As String 'holds either a vbYEs or vbNo
  296.             strResponse = MsgBox(strFriend & " wants to send you [" & strFileName & "].  Do you wish to receive this file?", vbYesNo, "File Exchange Requested") '<=- easy to understand
  297.             If strResponse = vbYes Then 'if they said yes
  298.                 Dim strType As String 'holds the type of file
  299.                 strType = Right(strFileName, 3) 'gets the type of file
  300.                 CD.FileName = strFileName 'sets the filename into the commondialog box
  301.                 CD.Filter = "File Type (*." & strType & ")|*." & strType 'sets the filter to the filetype
  302.                 CD.Flags = cdlOFNOverwritePrompt 'asks u if u want to overwrite file
  303.                 CD.ShowSave 'shows the save commondialog box
  304.                 Open CD.FileName For Binary As #1 'opens a file with the name and path u want
  305.                 Winsock.SendData "OKOK i want the file" 'tell client u want the damn file
  306.                 Me.Enabled = False 'disables to form to PREVENT ERROR!!!!!!!!!!
  307.             ElseIf strResponse = vbNo Then 'if they say no
  308.                 Winsock.SendData "Nope dont want it!" 'tell em u dont want their crap!
  309.                 DoEvents 'hmmm
  310.             End If 'ok enough of that madness
  311.         Case "Stop" 'the file exchange has ended
  312.             Close #1 'closes the file
  313.             'resets the progressbar
  314.             PBar.Value = 0
  315.             PBar.Max = 1
  316.             '=====================
  317.             Me.Enabled = True 'reenables the form!
  318.             DoEvents
  319.             Winsock.SendData "OKOKmore"
  320.         Case "Nick" 'client has sent u their name
  321.             strFriend = strData2 'saves their name into memory
  322.         Case "Nope" 'tells u that they declined ur request to give em a file
  323.             MsgBox strFriend & " declined your file transfer request.", vbInformation, "File Transfer Canceled!" '<=- easy to get again
  324.             Close #1 'closes the file
  325.             'stops the loops that was waiting for the boolean value to be true
  326.             Do
  327.             DoEvents
  328.             Loop
  329.             '==========================
  330.         Case "OKOK" 'tells u they want more of the file
  331.             If strData2 = "more" Then
  332.                 If lstSend.ListCount <> 0 Then
  333.                     cmdSend_Click
  334.                     Exit Sub
  335.                 Else
  336.                     Exit Sub
  337.                 End If
  338.             End If
  339.             Me.Enabled = False 'keeps form disabled
  340.             PBar.Max = strLOF 'sets progressbar max to filesize
  341.             If Not EOF(1) Then 'does this if not the end of the file
  342.                 If strLOF - Loc(1) < 2040 Then 'if you are at the last chunk of data
  343.                     strBlock = Space$(strLOF - Loc(1)) 'sets the block size to the size of the data (cause its less!)
  344.                     Get 1, , strBlock 'gets data
  345.                     Winsock.SendData "File" & strBlock 'sends data
  346.                     DoEvents ' =/
  347.                     PBar.Value = PBar.Value + Len(strBlock) 'sets progressbar
  348.                     strSoFar = strSoFar + (strLOF - Loc(1)) 'sets KBps
  349.                     Winsock.SendData "Stop the maddness!" 'tells client THE TRANSFER IS ENDED!
  350.                     Close #1 'closes file
  351.                     'resets the progressbar
  352.                     PBar.Max = 1
  353.                     PBar.Value = 0
  354.                     '====================
  355.                     Me.Enabled = True 'reenables the form
  356.                 Else 'if not the last chunk
  357.                     strBlock = Space$(2040) 'sets block up to receive only 2040 bytes of data
  358.                 End If
  359.                 strSoFar = strSoFar + 2040 'calculates KBps
  360.                 Get 1, , strBlock 'gets data
  361.                 Winsock.SendData "File" & strBlock 'sends data
  362.                 DoEvents
  363.                 PBar.Value = PBar.Value + Len(strBlock) 'sets progressbar
  364.             End If
  365.         Case "Chat" 'if they are talking to ya
  366.             txtChat.SelStart = Len(txtChat) 'sets cursor position in chatroom
  367.             txtChat.SelText = strFriend & ":" & vbTab & strData2 & vbCrLf 'puts the chat into the room
  368.     End Select
  369. End Sub
  370.